Leadtools.Dicom Namespace > DicomDataSet Class > SetModalityLut Method : SetModalityLut(Int32,DicomModalityLutAttributes,Int32[],DicomSetImageFlags) Method |
public void SetModalityLut( int frameIndex, DicomModalityLutAttributes attributes, int[] data, DicomSetImageFlags flags )
'Declaration Public Overloads Sub SetModalityLut( _ ByVal frameIndex As Integer, _ ByVal attributes As DicomModalityLutAttributes, _ ByVal data() As Integer, _ ByVal flags As DicomSetImageFlags _ )
'Usage Dim instance As DicomDataSet Dim frameIndex As Integer Dim attributes As DicomModalityLutAttributes Dim data() As Integer Dim flags As DicomSetImageFlags instance.SetModalityLut(frameIndex, attributes, data, flags)
public void SetModalityLut( int frameIndex, DicomModalityLutAttributes attributes, int[] data, DicomSetImageFlags flags )
public void setModalityLut(int frameIndex, DicomModalityLutAttributes attributes, int[]data, int dicomSetImageFlags)
function Leadtools.Dicom.DicomDataSet.SetModalityLut(Int32,DicomModalityLutAttributes,Int32[],DicomSetImageFlags)( frameIndex , attributes , data , flags )
public: void SetModalityLut( int frameIndex, DicomModalityLutAttributes^ attributes, array<int>^ data, DicomSetImageFlags flags )
If you are trying to set the "Rescale Intercept" (0028,1052) and "Rescale Slope" (0028,1053), set IsRescaleSlopeIntercept to true, and populate RescaleIntercept and DicomModalityLutAttributes.RescaleSlope with the new values. You can also populate RescaleType if you want to set "Rescale Type" (0028,1054).
If you are trying to set the elements under "Modality LUT Sequence", set IsModalityLutSequence to true, and populate FirstStoredPixelValueMapped, NumberOfEntries, EntryBits, and LutType. In this case, data should hold the "LUT Data" (0028,3006).
Tag | Name |
(0028,1052) | Rescale Intercept |
(0028,1053) | Rescale Slope |
(0028,1054) | Rescale Type |
Imports Leadtools Imports Leadtools.Dicom ''' Private Sub DicomDataSet_SetModalityLut2Example() Dim ds As DicomDataSet = New DicomDataSet() Dim flags As DicomDataSetInitializeFlags = DicomDataSetInitializeFlags.ExplicitVR Or DicomDataSetInitializeFlags.LittleEndian Or _ DicomDataSetInitializeFlags.AddMandatoryElementsOnly Or DicomDataSetInitializeFlags.AddMandatoryModulesOnly ' Initialize with class that supports multiframe functional groups ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags) ' Delete these items -- they will get added again later in the sample ' * Shared Functional Group2 Sequence ' * Per-frame Functional Group2 Sequence Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PerFrameFunctionalGroupsSequence, False) If Not element Is Nothing Then ds.DeleteElement(element) End If element = ds.FindFirstElement(Nothing, DicomTag.SharedFunctionalGroupsSequence, False) If Not element Is Nothing Then ds.DeleteElement(element) End If ' Add a modality LUT on 0th frame Dim modalityLutAttributes As DicomModalityLutAttributes = New DicomModalityLutAttributes() modalityLutAttributes.IsModalityLutSequence = False modalityLutAttributes.IsRescaleSlopeIntercept = True modalityLutAttributes.RescaleType = "UNSPECIFIED" modalityLutAttributes.RescaleIntercept = -128.0 modalityLutAttributes.RescaleSlope = 1.0 ds.SetModalityLut(0, modalityLutAttributes, Nothing, DicomSetImageFlags.MfgModalityLutPerFrame) ' Add a second modality LUT on the 1st frame modalityLutAttributes.RescaleIntercept = -156.0 modalityLutAttributes.RescaleSlope = 1.1 ds.SetModalityLut(1, modalityLutAttributes, Nothing, DicomSetImageFlags.MfgModalityLutPerFrame) ' Retrieve the modality LUT attributes from second frame (frameIndex == 1) Dim modalityLutAttributes2 As DicomModalityLutAttributes = ds.GetModalityLutAttributes(1) Dim sMsg As String = String.Format("Slope: {0}" & Constants.vbLf & "Intercept: {1}" & Constants.vbLf & "RescaleType {2}", _ modalityLutAttributes2.RescaleSlope, modalityLutAttributes2.RescaleIntercept, modalityLutAttributes2.RescaleType) MessageBox.Show(sMsg) ' Finally, delete the second modality LUT ds.DeleteModalityLut(1, DicomSetImageFlags.None) ' Save the file ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None) End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Dicom; /// void DicomDataSet_SetModalityLut2Example() { DicomDataSet ds = new DicomDataSet(); DicomDataSetInitializeFlags flags = DicomDataSetInitializeFlags.ExplicitVR | DicomDataSetInitializeFlags.LittleEndian | DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.AddMandatoryModulesOnly ; // Initialize with class that supports multiframe functional groups ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags); // Delete these items -- they will get added again later in the sample // * Shared Functional Group2 Sequence // * Per-frame Functional Group2 Sequence DicomElement element = ds.FindFirstElement(null, DicomTag.PerFrameFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); element = ds.FindFirstElement(null, DicomTag.SharedFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); // Add a modality LUT on 0th frame DicomModalityLutAttributes modalityLutAttributes = new DicomModalityLutAttributes(); modalityLutAttributes.IsModalityLutSequence = false; modalityLutAttributes.IsRescaleSlopeIntercept = true; modalityLutAttributes.RescaleType = "UNSPECIFIED"; modalityLutAttributes.RescaleIntercept = -128.0; modalityLutAttributes.RescaleSlope = 1.0; ds.SetModalityLut(0, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Add a second modality LUT on the 1st frame modalityLutAttributes.RescaleIntercept = -156.0; modalityLutAttributes.RescaleSlope = 1.1; ds.SetModalityLut(1, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Retrieve the modality LUT attributes from second frame (frameIndex == 1) DicomModalityLutAttributes modalityLutAttributes2 = ds.GetModalityLutAttributes(1); string sMsg = string.Format("Slope: {0}\nIntercept: {1}\nRescaleType {2}", modalityLutAttributes2.RescaleSlope, modalityLutAttributes2.RescaleIntercept, modalityLutAttributes2.RescaleType); MessageBox.Show(sMsg); // Finally, delete the second modality LUT ds.DeleteModalityLut(1, DicomSetImageFlags.None); // Save the file ds.Save(Path.Combine(LEAD_VARS.ImagesDir, "Test.dcm"), DicomDataSetSaveFlags.None); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
using Leadtools.Dicom.Constants; using Leadtools; using Leadtools.Dicom; /// async Task DicomDataSet_SetModalityLut2Example() { DicomDataSet ds = new DicomDataSet(); DicomDataSetInitializeFlags flags = DicomDataSetInitializeFlags.ExplicitVR | DicomDataSetInitializeFlags.LittleEndian | DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.AddMandatoryModulesOnly ; // Initialize with class that supports multiframe functional groups ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags); // Delete these items -- they will get added again later in the sample // * Shared Functional Group2 Sequence // * Per-frame Functional Group2 Sequence DicomElement element = ds.FindFirstElement(null, DicomTagConstants.PerFrameFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); element = ds.FindFirstElement(null, DicomTagConstants.SharedFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); // Add a modality LUT on 0th frame DicomModalityLutAttributes modalityLutAttributes = new DicomModalityLutAttributes(); modalityLutAttributes.IsModalityLutSequence = false; modalityLutAttributes.IsRescaleSlopeIntercept = true; modalityLutAttributes.RescaleType = "UNSPECIFIED"; modalityLutAttributes.RescaleIntercept = -128.0; modalityLutAttributes.RescaleSlope = 1.0; ds.SetModalityLut(0, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Add a second modality LUT on the 1st frame modalityLutAttributes.RescaleIntercept = -156.0; modalityLutAttributes.RescaleSlope = 1.1; ds.SetModalityLut(1, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Retrieve the modality LUT attributes from second frame (frameIndex == 1) DicomModalityLutAttributes modalityLutAttributes2 = ds.GetModalityLutAttributes(1); string sMsg = string.Format("Slope: {0}\nIntercept: {1}\nRescaleType {2}", modalityLutAttributes2.RescaleSlope, modalityLutAttributes2.RescaleIntercept, modalityLutAttributes2.RescaleType); Debug.WriteLine(sMsg); // Finally, delete the second modality LUT ds.DeleteModalityLut(1, DicomSetImageFlags.None); // Save the file string dicomFileNameOutput = "Test.dcm"; StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(dicomFileNameOutput); ILeadStream streamOutput = LeadStreamFactory.Create(saveFile); using (IDisposable disposableOUT = streamOutput as IDisposable) { await ds.SaveAsync(streamOutput, DicomDataSetSaveFlags.None); } }
using Leadtools; using Leadtools.Dicom; using Leadtools.Examples; void DicomDataSet_SetModalityLut2Example(Stream outputStream) { DicomDataSet ds = new DicomDataSet(); DicomDataSetInitializeFlags flags = DicomDataSetInitializeFlags.ExplicitVR | DicomDataSetInitializeFlags.LittleEndian | DicomDataSetInitializeFlags.AddMandatoryElementsOnly | DicomDataSetInitializeFlags.AddMandatoryModulesOnly ; // Initialize with class that supports multiframe functional groups ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags); // Delete these items -- they will get added again later in the sample // * Shared Functional Group2 Sequence // * Per-frame Functional Group2 Sequence DicomElement element = ds.FindFirstElement(null, DicomTag.PerFrameFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); element = ds.FindFirstElement(null, DicomTag.SharedFunctionalGroupsSequence, false); if (element != null) ds.DeleteElement(element); // Add a modality LUT on 0th frame DicomModalityLutAttributes modalityLutAttributes = new DicomModalityLutAttributes(); modalityLutAttributes.IsModalityLutSequence = false; modalityLutAttributes.IsRescaleSlopeIntercept = true; modalityLutAttributes.RescaleType = "UNSPECIFIED"; modalityLutAttributes.RescaleIntercept = -128.0; modalityLutAttributes.RescaleSlope = 1.0; ds.SetModalityLut(0, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Add a second modality LUT on the 1st frame modalityLutAttributes.RescaleIntercept = -156.0; modalityLutAttributes.RescaleSlope = 1.1; ds.SetModalityLut(1, modalityLutAttributes, null, DicomSetImageFlags.MfgModalityLutPerFrame); // Retrieve the modality LUT attributes from second frame (frameIndex == 1) DicomModalityLutAttributes modalityLutAttributes2 = ds.GetModalityLutAttributes(1); string sMsg = string.Format("Slope: {0}\nIntercept: {1}\nRescaleType {2}", modalityLutAttributes2.RescaleSlope, modalityLutAttributes2.RescaleIntercept, modalityLutAttributes2.RescaleType); Debug.WriteLine(sMsg); // Finally, delete the second modality LUT ds.DeleteModalityLut(1, DicomSetImageFlags.None); // Save the file ds.Save(outputStream, DicomDataSetSaveFlags.None); }
Imports Leadtools Imports Leadtools.Dicom Private Sub DicomDataSet_SetModalityLut2Example(ByVal outputStream As Stream) Dim ds As DicomDataSet = New DicomDataSet() Dim flags As DicomDataSetInitializeFlags = DicomDataSetInitializeFlags.ExplicitVR Or _ DicomDataSetInitializeFlags.LittleEndian Or _ DicomDataSetInitializeFlags.AddMandatoryElementsOnly Or _ DicomDataSetInitializeFlags.AddMandatoryModulesOnly ' Initialize with class that supports multiframe functional groups ds.Initialize(DicomClassType.EnhancedMRImageStorage, flags) ' Delete these items -- they will get added again later in the sample ' * Shared Functional Group2 Sequence ' * Per-frame Functional Group2 Sequence Dim element As DicomElement = ds.FindFirstElement(Nothing, DicomTag.PerFrameFunctionalGroupsSequence, False) If Not element Is Nothing Then ds.DeleteElement(element) End If element = ds.FindFirstElement(Nothing, DicomTag.SharedFunctionalGroupsSequence, False) If Not element Is Nothing Then ds.DeleteElement(element) End If ' Add a modality LUT on 0th frame Dim modalityLutAttributes As DicomModalityLutAttributes = New DicomModalityLutAttributes() modalityLutAttributes.IsModalityLutSequence = False modalityLutAttributes.IsRescaleSlopeIntercept = True modalityLutAttributes.RescaleType = "UNSPECIFIED" modalityLutAttributes.RescaleIntercept = -128.0 modalityLutAttributes.RescaleSlope = 1.0 ds.SetModalityLut(0, modalityLutAttributes, Nothing, DicomSetImageFlags.MfgModalityLutPerFrame) ' Add a second modality LUT on the 1st frame modalityLutAttributes.RescaleIntercept = -156.0 modalityLutAttributes.RescaleSlope = 1.1 ds.SetModalityLut(1, modalityLutAttributes, Nothing, DicomSetImageFlags.MfgModalityLutPerFrame) ' Retrieve the modality LUT attributes from second frame (frameIndex == 1) Dim modalityLutAttributes2 As DicomModalityLutAttributes = ds.GetModalityLutAttributes(1) Dim sMsg As String = String.Format("Slope: {0}" _ & Constants.vbLf _ & "Intercept: {1}" _ & Constants.vbLf _ & "RescaleType {2}", _ modalityLutAttributes2.RescaleSlope, _ modalityLutAttributes2.RescaleIntercept, _ modalityLutAttributes2.RescaleType) Debug.WriteLine(sMsg) ' Finally, delete the second modality LUT ds.DeleteModalityLut(1, DicomSetImageFlags.None) ' Save the file ds.Save(outputStream, DicomDataSetSaveFlags.None) End Sub